<?php
	require_once('../inc/fen_fns.php');
	
	sec_session_start();
	$pid = $_GET['pid'];
	
	if(login_check($mysqli, '>', '50') == true) {

						$query = $_DB->Query("SELECT
											fen_members.titr as titr,
											fen_members.name as name,
											fen_members.surname as surname,
											fen_members.username as username,
											fen_department.department_name as department_name,
											fen_faculty.faculty_name as faculty_name,
											fen_toplanti.toplanti_adi,
											fen_toplanti.ulke,
											fen_toplanti.sehir,	
											date_FORMAT(fen_toplanti.tarih1, '%d/%m/%Y') as tarih1,		
											date_FORMAT(fen_toplanti.tarih2, '%d/%m/%Y') as tarih2,
											DATEDIFF(tarih2, tarih1) as gun_sayisi,
											fen_toplanti.bildiri_konusu,
											fen_toplanti.baska_destek,
											fen_toplanti.baska_destek1,
											fen_toplanti.baska_destek2,
											fen_toplanti.baska_destek3,
											fen_toplanti.baska_destek_diger,
											fen_toplanti.talep_sebebi1,
											fen_toplanti.talep_sebebi2,
											fen_toplanti.talep_sebebi3,
											fen_toplanti.destek_turu,
											fen_toplanti.tutar,
											fen_toplanti.odenen_tutar,
											fen_toplanti.para_birimi,
											fen_toplanti.ders_durumu,
											fen_toplanti.telafi_ders_adi,
											fen_toplanti.telafi_kim,
											fen_toplanti.telafi_sinif,
											fen_toplanti.telafi_tarih,
											fen_toplanti.telafi_hoca	
											from fen_members, fen_department, fen_faculty, fen_toplanti
											WHERE
											fen_toplanti.id = '".$pid."' and
											fen_toplanti.member_id = fen_members.id and
											fen_members.department_id = fen_department.id and
											fen_members.faculty_id = fen_faculty.id
											");
						
						
							$sebep = array();
							$sebepfinal = "";
							
							$talep_sebebi1 = "";
							$talep_sebebi2 = "";
							$talep_sebebi3 = "";						
							
							if ($_DB->GetResultValue($query, "0", "talep_sebebi1") == '1') { array_push($sebep, "Yol"); }						
							if ($_DB->GetResultValue($query, "0", "talep_sebebi2") == '1') { array_push($sebep, "Kayıt"); }				
							if ($_DB->GetResultValue($query, "0", "talep_sebebi3") == '1') { array_push($sebep, "Harcırah"); }
							
							for ($x = 0; $x < count($sebep); $x++)
							{
							$sebepfinal .= $sebep[$x];  // The current element
								if ($x != count($sebep)-1) {
									$sebepfinal .= ", ";
								} 
							}
							
							if ($_DB->GetResultValue($query, "0", "odenen_tutar") > 0) {
								$odenen = $_DB->GetResultValue($query, "0", "odenen_tutar")." ".$_DB->GetResultValue($query, "0", "para_birimi");
							} else {
								$odenen = "Henüz ödenmedi";
							}
							
							$telafi_ders_adi = unserialize($_DB->GetResultValue($query, "0", "telafi_ders_adi"));
							$telafi_kim = unserialize($_DB->GetResultValue($query, "0", "telafi_kim"));
							$telafi_sinif = unserialize($_DB->GetResultValue($query, "0", "telafi_sinif"));
							$telafi_tarih = unserialize($_DB->GetResultValue($query, "0", "telafi_tarih"));
							$telafi_hoca = unserialize($_DB->GetResultValue($query, "0", "telafi_hoca"));
							
							
							$telafi_cizgi = array();
							if ($telafi_kim[0] == 'Kendim') { $telafi_cizgi[0] = "-";  } else { $telafi_cizgi[0] = ""; }
							if ($telafi_kim[1] == 'Kendim') { $telafi_cizgi[1] = "-";  } else { $telafi_cizgi[1] = ""; }
							if ($telafi_kim[2] == 'Kendim') { $telafi_cizgi[2] = "-";  } else { $telafi_cizgi[2] = ""; }
							if ($telafi_kim[3] == 'Kendim') { $telafi_cizgi[3] = "-";  } else { $telafi_cizgi[3] = ""; }
							
							$gun_sayisi = $_DB->GetResultValue($query, "0", "gun_sayisi") + 1;
						
				
						
?>

<script type="text/javascript">


function cancelReason(obj) {  

	jQuery(document).ready(function($) {
		  $('a[rel*=facebox]').facebox() 

		  jQuery.facebox({ ajax: 'applications/application-cancel.php?pid='+obj })
	}) 
} 



</script>


	<div id="user_detailed_div">
<div id="user_detailed_head_div">
<p id="user_detailed_name">&nbsp;
<?php 
			
				echo $_DB->GetResultValue($query, "0", "titr")." ".$_DB->GetResultValue($query, "0", "name")." ".$_DB->GetResultValue($query, "0", "surname");
		
?>
</p>
</div>


<div class="summaryTableSmall2detailed2">

	<table id="appDetailedTable">
		<tr>
			<td id="appDetailedTD">Fakülte</td>
			<td id="appDetailedTD2a"><?php echo $_DB->GetResultValue($query, "0", "faculty_name"); ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Bölüm</td>
			<td id="appDetailedTD2"><font color="#188cb6"><?php echo $_DB->GetResultValue($query, "0", "department_name"); ?></b></font></td>
		</tr>
	</table>
	<br>
	<table id="appDetailedTable">		
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Toplantı Adı</td>
			<td id="appDetailedTD2a"><?php echo $_DB->GetResultValue($query, "0", "toplanti_adi"); ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Ülke</td>
			<td id="appDetailedTD2"><?php echo $_DB->GetResultValue($query, "0", "ulke"); ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Şehir</td>
			<td id="appDetailedTD2"><?php echo $_DB->GetResultValue($query, "0", "sehir"); ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Toplantı Tarihi</td>
			<td id="appDetailedTD2"><?php echo $_DB->GetResultValue($query, "0", "tarih1")." - ".$_DB->GetResultValue($query, "0", "tarih2")." <font color=\"#188cb6\">(".$gun_sayisi." gün)</font>"; ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Bildiri Konusu</td>
			<td id="appDetailedTD2"><?php echo $_DB->GetResultValue($query, "0", "bildiri_konusu"); ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Talep Nedeni</td>
			<td id="appDetailedTD2"><?php echo $sebepfinal; ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Destek Türü</td>
			<td id="appDetailedTD2"><?php echo $_DB->GetResultValue($query, "0", "destek_turu"); ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">İstenen Tutar</td>
			<td id="appDetailedTD2"><?php echo $_DB->GetResultValue($query, "0", "tutar")." ".$_DB->GetResultValue($query, "0", "para_birimi"); ?></td>
		</tr>
		<tr id="appDetailedTR">
			<td id="appDetailedTD">Ödenen Tutar</td>
			<td id="appDetailedTD2"><?php echo $odenen; ?></td>
		</tr>
		<tr>
			<td id="appDetailedTD">Ders Durumu</td>
			<td id="appDetailedTD2"><?php echo $_DB->GetResultValue($query, "0", "ders_durumu"); ?></td>
		</tr>
	</table>
	<br>
<?php 
	if (count($telafi_ders_adi) > 0 && strlen($telafi_ders_adi[0]) > 3) { 
?>	
		<table id="tablemeetingdetailedhead">
			<tr>
				<td width="38%">
					&nbsp;&nbsp;Ders Adı
				</td>
				<td width="30%">
					Telafi Tarihi ve sınıf
				</td>
				<td width="32%">
					Telafi Edecek Öğretim Üyesi&nbsp;
				</td>
			</tr>
		</table>

<?php 	
		for ($i=0; $i<count($telafi_ders_adi); $i++) {
?>
			<table id="tablemeetingdetailed<?php if ($i%2 != 0) { echo "g"; } ?>">
				<tr>
					<td width="38%">
						&nbsp;&nbsp;<?php echo $telafi_ders_adi[$i]; ?>
					</td>
					<td width="30%">
						<?php echo $telafi_tarih[$i]." ".$telafi_cizgi[$i]." ".$telafi_sinif[$i]; ?>
					</td>
					<td width="32%">
						<?php echo $telafi_hoca[$i]; ?>
					</td>
				</tr>	
			</table>
<?php 	
		}
		echo "<br>";
	}
?>
	
		
				
</div>

<?php 
	} else {
		header('Location: ./index.php?error=2');
	}

?>